﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using CinemaBookingGUI.CinemaServiceReference;

namespace CinemaBookingGUI
{
    public partial class cinemaProgram : Form
    {
        private CinemaServiceReference.ICinemaWcf cinemaWcf = new CinemaServiceReference.CinemaWcfClient();
        private BookingServiceReference.IBookingSeats bookingWcf = new BookingServiceReference.BookingSeatsClient();

        public cinemaProgram()
        {
            InitializeComponent();
            this.CenterToScreen();
            loadData();
            loadMovies();
            loadScreenings();
            loadOrders();
        }

        #region Load Other Data Method
        private void loadData()
        {
            //Input auditorium id values and corresponding names into drop down box for screenings.
            //screeningAuditoriumIDBox.DataSource = bookingCtr.GetAuditoriumList();
            screeningAuditoriumIDBox.DataSource = cinemaWcf.GetAllAuditoriums();
            screeningAuditoriumIDBox.DisplayMember = "AuditoriumName";
            screeningAuditoriumIDBox.ValueMember = "AuditoriumID";

            //Input movie id values and corresponding titles into drop down box for screenings.
            //screeningMovieIDBox.DataSource = bookingCtr.GetMovieList();
            screeningMovieIDBox.DataSource = cinemaWcf.GetAllMovies();
            screeningMovieIDBox.DisplayMember = "MovieTitle";
            screeningMovieIDBox.ValueMember = "MovieID";

            //Input list for number of seats to book.
            List<int> numberOfSeats = new List<int>();
            numberOfSeats.Add(1);
            numberOfSeats.Add(2);
            numberOfSeats.Add(3);
            numberOfSeats.Add(4);
            numberOfSeats.Add(5);
            orderNumberOfSeatsBox.DataSource = numberOfSeats;

            #region To be removed
            ////BookingController.GetScreeningList();
            //List<CinemaScreening> screeningList = cinemaWcf.GetAllScreenings().ToList();

            //List<int> showingMovieIDList = new List<int>();

            //foreach (CinemaScreening screening in screeningList)
            //{
            //    if (!showingMovieIDList.Contains(screening.MovieID))
            //    {
            //        showingMovieIDList.Add(screening.MovieID);
            //    }
            //}

            ////BookingController.GetMovieList();
            //List<CinemaMovie> movieList = cinemaWcf.GetAllMovies().ToList();

            //List<CinemaMovie> showingMovieList = new List<CinemaMovie>();

            ////BookingController.GetShowingMovieList();
            //foreach (CinemaMovie movie in movieList)
            //{
            //    if (showingMovieIDList.Contains(movie.MovieID))
            //    {
            //        showingMovieList.Add(movie);
            //    }
            //}
#endregion
            //Input movie id values and corresponding titles into drop down box for orders.
            orderMovieBox.DataSource = cinemaWcf.GetMoviesWhichHasScreeningID();
            orderMovieBox.DisplayMember = "MovieTitle";
            orderMovieBox.ValueMember = "MovieID";

            #region To be removed
            //List<CinemaScreening> movieScreenings = new List<CinemaScreening>();

            //int chosenMovieID = int.Parse(orderMovieBox.SelectedValue.ToString());

            //foreach (CinemaScreening screening in screeningList)
            //{
            //    if (screening.MovieID == chosenMovieID)
            //    {
            //        movieScreenings.Add(screening);
            //    }
            //}
#endregion
            //Input available screenings for the currently chosen movie.
            orderScreeningBox.DataSource = cinemaWcf.GetCurrentScreeningByMovieID(int.Parse(orderMovieBox.SelectedValue.ToString()));
            orderScreeningBox.DisplayMember = "ScreeningStartDateTime";
            orderScreeningBox.ValueMember = "ScreeningID";

            #region To be removed
            //List<CinemaRow> rowList = cinemaWcf.GetAllRows().ToList();
            
            //int chosenScreeningID = int.Parse(orderScreeningBox.SelectedValue.ToString());

            //List<CinemaAuditorium> auditoriumList = cinemaWcf.GetAllAuditoriums().ToList();

            //int chosenAuditoriumID = 0;

            //foreach (CinemaScreening screening in screeningList)
            //{
            //    if (screening.ScreeningID == chosenScreeningID)
            //    {
            //        chosenAuditoriumID = screening.AuditoriumID;
            //        break;
            //    }
            //}

            //List<CinemaRow> auditoriumRowList = new List<CinemaRow>();

            //foreach (CinemaRow row in rowList)
            //{
            //    if (row.AuditoriumID == chosenAuditoriumID)
            //    {
            //        auditoriumRowList.Add(row);
            //    }
            //}
#endregion
            //Input rows from the chosen screenings auditorium.
            orderRowNumberBox.DataSource = cinemaWcf.GetRowsByScreeningID(int.Parse(orderScreeningBox.SelectedValue.ToString()));
            orderRowNumberBox.DisplayMember = "RowNumber";
            orderRowNumberBox.ValueMember = "RowsID";

            #region To be removed
            //int chosenRowID = int.Parse(orderRowNumberBox.SelectedValue.ToString());

            //List<CinemaSeat> seatList = cinemaWcf.GetAllSeats().ToList();

            //List<CinemaBookedSeat> bookedSeatList = cinemaWcf.GetAllBookedSeats().ToList();

            //List<CinemaSeat> rowSeatList = new List<CinemaSeat>();

            //foreach (CinemaSeat seat in seatList)
            //{
            //    if (seat.RowID == chosenRowID)
            //    {
            //        bool seatBooked = false;
            //        foreach (CinemaBookedSeat bookedSeat in bookedSeatList)
            //        {
            //            if (bookedSeat.SeatID == seat.SeatID && bookedSeat.ScreeningID == chosenScreeningID)
            //            {
            //                seatBooked = true;
            //                break;
            //            }
            //        }
            //        if (!seatBooked)
            //        {
            //            rowSeatList.Add(seat);
            //        }
            //    }
            //}
#endregion
            //Input unbooked seats for the chosen row number.
            orderSeatNumberBox.DataSource = cinemaWcf.GetAllSeatsNotBookedByRowID(int.Parse(orderScreeningBox.SelectedValue.ToString()), int.Parse(orderRowNumberBox.SelectedValue.ToString()));
            orderSeatNumberBox.DisplayMember = "SeatNumber";
            orderSeatNumberBox.ValueMember = "SeatID";
        }
        #endregion

        #region Load Tabs Data Methods
        private void loadOrders()
        {
            orderListView.DataSource = cinemaWcf.GetAllOrders();
            orderColumnOrder();
        }

        private void loadPartOrder(int orderID)
        {
            List<CinemaPartOrder> orderPartOrderList = cinemaWcf.getAllPartOrdersOnOrder(orderID).ToList();
            partOrderListView.DataSource = orderPartOrderList;
            partOrderColumnOrder();
        }

        private void loadScreenings()
        {
            screeningListView.DataSource = cinemaWcf.GetAllScreenings();
            screeningColumnOrder();
        }

        private void loadMovies()
        {
            movieListView.DataSource = cinemaWcf.GetAllMovies();
            movieColumnOrder();
        }
        #endregion

        #region Column Order Methods
        private void movieColumnOrder()
        {
            movieListView.Columns["MovieID"].Visible = false;
            movieListView.Columns["MovieID"].DisplayIndex = 0;
            movieListView.Columns["MovieTitle"].DisplayIndex = 1;
            movieListView.Columns["MovieTitle"].HeaderText = "Title";
            movieListView.Columns["MovieDescription"].DisplayIndex = 2;
            movieListView.Columns["MovieDescription"].HeaderText = "Description";
            movieListView.Columns["MoviePrice"].DisplayIndex = 3;
            movieListView.Columns["MoviePrice"].HeaderText = "Price";
            movieListView.Columns["MoviePoster"].Visible = false;
        }

        private void screeningColumnOrder()
        {
            screeningListView.Columns["ScreeningID"].DisplayIndex = 0;
            screeningListView.Columns["ScreeningID"].Visible = false;
            screeningListView.Columns["MovieID"].DisplayIndex = 1;
            screeningListView.Columns["MovieID"].HeaderText = "Movie ID";
            screeningListView.Columns["MovieID"].Visible = true;
            screeningListView.Columns["AuditoriumID"].DisplayIndex = 2;
            screeningListView.Columns["AuditoriumID"].HeaderText = "Auditorium ID";
            screeningListView.Columns["AuditoriumID"].Visible = true;
            screeningListView.Columns["ScreeningStartDateTime"].DisplayIndex = 3;
            screeningListView.Columns["ScreeningStartDateTime"].HeaderText = "Start Date and Time";
            screeningListView.Columns["ScreeningEndDateTime"].DisplayIndex = 4;
            screeningListView.Columns["ScreeningEndDateTime"].HeaderText = "End Date and Time";
        }

        private void orderColumnOrder()
        {
            orderListView.Columns["OrderID"].Visible = false;
            orderListView.Columns["OrderID"].DisplayIndex = 0;
            orderListView.Columns["OrderName"].DisplayIndex = 1;
            orderListView.Columns["OrderName"].HeaderText = "Customer Name";
            orderListView.Columns["OrderPhone"].DisplayIndex = 2;
            orderListView.Columns["OrderPhone"].HeaderText = "Customer Phone Number";
        }

        private void partOrderColumnOrder()
        {
            partOrderListView.Columns["PartOrderID"].Visible = false;
            partOrderListView.Columns["PartOrderID"].DisplayIndex = 0;
            partOrderListView.Columns["OrderID"].Visible = false;
            partOrderListView.Columns["OrderID"].DisplayIndex = 1;
            partOrderListView.Columns["ScreeningID"].DisplayIndex = 2;
            partOrderListView.Columns["ScreeningID"].HeaderText = "Screening ID";
            partOrderListView.Columns["SeatID"].DisplayIndex = 3;
            partOrderListView.Columns["SeatID"].HeaderText = "Seat ID";
        }
        #endregion

        #region Interface Interaction Methods
        private void cinemaTabs_Selecting(object sender, TabControlCancelEventArgs e)
        {
            loadData();
        }

        private void orderListView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            orderNameBox.Text = orderListView.CurrentRow.Cells[1].Value.ToString();
            orderPhoneBox.Text = orderListView.CurrentRow.Cells[2].Value.ToString();
            loadPartOrder(int.Parse(orderListView.CurrentRow.Cells[0].Value.ToString()));
        }

        private void screeningListView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            screeningMovieIDBox.SelectedValue = int.Parse(screeningListView.CurrentRow.Cells[1].Value.ToString());
            screeningAuditoriumIDBox.SelectedValue = int.Parse(screeningListView.CurrentRow.Cells[2].Value.ToString());
            screeningStartDateTimePicker.Value = DateTime.Parse(screeningListView.CurrentRow.Cells[3].Value.ToString());
            screeningEndDateTimePicker.Value = DateTime.Parse(screeningListView.CurrentRow.Cells[4].Value.ToString());
        }

        private void movieListView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            movieTitleBox.Text = movieListView.CurrentRow.Cells[1].Value.ToString();
            movieDescriptionBox.Text = movieListView.CurrentRow.Cells[2].Value.ToString();
            moviePriceBox.Text = movieListView.CurrentRow.Cells[3].Value.ToString();
        }
        #endregion

        #region Update Methods
        //private void UpdateSomething()
        //{
            
        //}
        #endregion

        #region Order Methods
        private void clearOrderTextBoxes()
        {
            orderNameBox.Clear();
            orderPhoneBox.Clear();
        }

        private void clearOrderFields(object sender, EventArgs e)
        {
            clearOrderTextBoxes();
        }

        private void createOrder(object sender, EventArgs e)
        {
            bool properName = false;
            string orderName = orderNameBox.Text.Trim();
            if (!string.IsNullOrWhiteSpace(orderName))
            {
                properName = true;
            }

            bool properPhone = false;
            int orderPhone = 0;
            try
            {
                orderPhone = Convert.ToInt32(orderPhoneBox.Text.Trim());
                properPhone = true;
            }
            catch (Exception)
            { }

            int orderScreeningID = int.Parse(orderScreeningBox.SelectedValue.ToString());

            int orderNumberOfSeats = int.Parse(orderNumberOfSeatsBox.SelectedValue.ToString());

            int orderSeatChoiceID = int.Parse(orderSeatNumberBox.SelectedValue.ToString());

            if (properName && properPhone)
            {
                bool orderCreated = bookingWcf.CreateBooking(orderNumberOfSeats, orderSeatChoiceID, orderScreeningID, orderName, orderPhone);
                clearOrderTextBoxes();
                loadOrders();
                loadData();
                if (orderCreated)
                {
                    MessageBox.Show("Order was created with Customer Name: \"" + orderName + "\", Customer Phone Number: \"" + orderPhone + "\", Screening ID: \"" + orderScreeningID + "\" and Number of Seats: \"" + orderNumberOfSeats + "\"", "Order Creation Succeeded!");
                }
                else if (!orderCreated)
                {
                    MessageBox.Show("Order was not created because not enough seats were available in the chosen row area. Try choosing a different row or different side on the same row. (try to avoid rows where there is not enough consecutive seats for the number of seats you want to book)", "Order Creation Cancelled - Not Enough Seats Available!");
                }
            }
            else
            {
                string errorMessages = "";
                if (!properName)
                {
                    errorMessages = "missing customer name";
                }
                if (!properPhone)
                {
                    if (!properName)
                    {
                        errorMessages += " and invalid phone number";
                    }
                    else
                    {
                        errorMessages = "invalid phone number";
                    }
                }
                MessageBox.Show("Order was not created due to " + errorMessages + ".", "Order Creation Cancelled - Invalid Input!");
            }
        }

        private void deleteOrder(object sender, EventArgs e)
        {
            DialogResult confirmDelete = MessageBox.Show("Are you sure you want to delete the selected order?", "Order Deletion Warning!", MessageBoxButtons.YesNo);
            if (confirmDelete == DialogResult.Yes)
            {
                int selectedOrderID = int.Parse(orderListView.CurrentRow.Cells[0].Value.ToString());
                cinemaWcf.DeleteOrder(selectedOrderID);
                loadOrders();
                MessageBox.Show("Order with ID: " + selectedOrderID + " has been deleted from the database.", "Attention!");
            }
        }
        #endregion

        #region Screening Methods
        private void clearScreeningTextBoxes()
        {
            screeningAuditoriumIDBox.SelectedIndex = 0;
            screeningMovieIDBox.SelectedIndex = 0;
            screeningStartDateTimePicker.Value = DateTime.Now;
            screeningEndDateTimePicker.Value = DateTime.Now;
        }

        private void clearScreeningFields(object sender, EventArgs e)
        {
            clearScreeningTextBoxes();
        }

        private void createScreening(object sender, EventArgs e)
        {
            int auditoriumID = int.Parse(screeningAuditoriumIDBox.SelectedValue.ToString());

            int movieID = int.Parse(screeningMovieIDBox.SelectedValue.ToString());

            //The start date cannot be before today's date.
            bool properStartDate = false;
            DateTime startDate = screeningStartDateTimePicker.Value;
            if (startDate.CompareTo(DateTime.Now) > 0)
            {
                properStartDate = true;
            }

            //The end date cannot be before the start date.
            bool properEndDate = false;
            DateTime endDate = screeningEndDateTimePicker.Value;
            if (endDate.CompareTo(startDate) > 0)
            {
                properEndDate = true;
            }

            if (properStartDate && properEndDate)
            {
                int selectedScreeningID = int.Parse(screeningListView.CurrentRow.Cells[0].Value.ToString());
                cinemaWcf.InsertScreening(movieID, auditoriumID, startDate, endDate);
                clearScreeningTextBoxes();
                loadScreenings();
                MessageBox.Show("Screening was created with Movie ID: \"" + movieID + "\", Auditorium ID: \"" + auditoriumID + "\", Start Date: \"" + startDate + "\" and End Date: \"" + endDate + "\"", "Screening Creation Succeeded!");
            }
            else
            {
                string errorMessages = "";
                if (!properStartDate)
                {
                    errorMessages = "the start date and time has to exceed the current time";
                }
                if (!properEndDate)
                {
                    if (!properStartDate)
                    {
                        errorMessages += " and the end date and time has to exceed the start time";
                    }
                    else
                    {
                        errorMessages = "the end date and time has to exceed the start time";
                    }
                }
                MessageBox.Show("Screening was not created because " + errorMessages + ".", "Screening Creation Cancelled!");
            }
        }

        private void editScreening(object sender, EventArgs e)
        {
            int auditoriumID = int.Parse(screeningAuditoriumIDBox.SelectedValue.ToString());

            int movieID = int.Parse(screeningMovieIDBox.SelectedValue.ToString());

            //The start date cannot be before today's date.
            bool properStartDate = false;
            DateTime startDate = screeningStartDateTimePicker.Value;
            if (startDate.CompareTo(DateTime.Now) > 0)
            {
                properStartDate = true;
            }

            //The end date cannot be before the start date.
            bool properEndDate = false;
            DateTime endDate = screeningEndDateTimePicker.Value;
            if (endDate.CompareTo(startDate) > 0)
            {
                properEndDate = true;
            }

            if (properStartDate && properEndDate)
            {
                string oldScreeningMovieID = screeningListView.CurrentRow.Cells[1].Value.ToString();
                string oldScreeningAuditoriumID = screeningListView.CurrentRow.Cells[2].Value.ToString();
                string oldScreeningStartDate = screeningListView.CurrentRow.Cells[3].Value.ToString();
                string oldScreeningEndDate = screeningListView.CurrentRow.Cells[4].Value.ToString();
                int selectedScreeningID = int.Parse(screeningListView.CurrentRow.Cells[0].Value.ToString());
                cinemaWcf.UpdateScreening(selectedScreeningID, movieID, auditoriumID, startDate, endDate);
                clearScreeningTextBoxes();
                loadScreenings();
                MessageBox.Show("Screening was edited from Movie ID: \"" + oldScreeningMovieID + "\", Auditorium ID: \"" + oldScreeningAuditoriumID + "\", Start Date: \"" + oldScreeningStartDate + "\" and End Date: \"" + oldScreeningEndDate + "\", to Movie ID: \"" + movieID + "\", Auditorium ID: \"" + auditoriumID + "\", Start Date: \"" + startDate + "\" and End Date: \"" + endDate + "\"", "Screening Edit Succeeded!");
            }
            else
            {
                string errorMessages = "";
                if (!properStartDate)
                {
                    errorMessages = "the start date and time has to exceed the current time";
                }
                if (!properEndDate)
                {
                    if (!properStartDate)
                    {
                        errorMessages += " and the end date and time has to exceed the start time";
                    }
                    else
                    {
                        errorMessages = "the end date and time has to exceed the start time";
                    }
                }
                MessageBox.Show("Screening was not edited because " + errorMessages + ".", "Screening Edit Cancelled!");
            }
        }

        private void deleteScreening(object sender, EventArgs e)
        {
            DialogResult confirmDelete = MessageBox.Show("Are you sure you want to delete the selected screening?", "Screening Deletion Warning!", MessageBoxButtons.YesNo);
            if (confirmDelete == DialogResult.Yes)
            {
                int selectedScreeningID = int.Parse(screeningListView.CurrentRow.Cells[0].Value.ToString());
                cinemaWcf.DeleteScreening(selectedScreeningID);
                loadScreenings();
                MessageBox.Show("Screening with ID: " + selectedScreeningID + " has been deleted from the database.", "Attention!");
            }
        }
        #endregion

        #region Movie Methods
        private void clearMovieTextBoxes()
        {
            movieTitleBox.Clear();
            movieDescriptionBox.Clear();
            moviePriceBox.Clear();
        }

        private void clearMovieFields(object sender, EventArgs e)
        {
            clearMovieTextBoxes();
        }

        private void createMovie(object sender, EventArgs e)
        {
            bool properTitle = false;
            string movieTitle = movieTitleBox.Text.Trim();
            if (!string.IsNullOrWhiteSpace(movieTitle))
            {
                properTitle = true;
            }

            bool properDescription = false;
            string movieDescription = movieDescriptionBox.Text.Trim();
            if (!string.IsNullOrWhiteSpace(movieDescription))
            {
                properDescription = true;
            }

            bool properPrice = false;
            double moviePrice = 0;
            try
            {
                moviePrice = Convert.ToDouble(moviePriceBox.Text.Trim());
                properPrice = true;
            }
            catch (Exception)
            { }

            if (properTitle && properPrice && properDescription)
            {
                cinemaWcf.InsertMovie(movieTitle, movieDescription, moviePrice);
                clearMovieTextBoxes();
                loadMovies();
                MessageBox.Show("Movie was created with Title: \"" + movieTitle + "\", Description: \"" + movieDescription + "\" and Price: \"" + moviePrice + "\"", "Movie Creation Succeeded!");
            }
            else
            {
                string errorMessages = "";
                if (!properTitle)
                {
                    errorMessages += "missing title input";
                }
                if (!properDescription)
                {
                    if (!properTitle && !properPrice)
                    {
                        errorMessages += ", missing description input";
                    }
                    else if (!properTitle && properPrice)
                    {
                        errorMessages += " and missing description input";
                    }
                    else
                    {
                        errorMessages += "missing description input";
                    }
                }
                if (!properPrice)
                {
                    if (!properTitle || !properDescription)
                    {
                        errorMessages += " and incorrect price input";
                    }
                    else
                    {
                        errorMessages += "incorrect price input";
                    }
                }
                MessageBox.Show("Movie was not created due to " + errorMessages + ".", "Movie Creation Cancelled!");
            }
        }

        private void editMovie(object sender, EventArgs e)
        {
            bool properTitle = false;
            string movieTitle = movieTitleBox.Text.Trim();
            if (!string.IsNullOrWhiteSpace(movieTitle))
            {
                properTitle = true;
            }

            bool properDescription = false;
            string movieDescription = movieDescriptionBox.Text.Trim();
            if (!string.IsNullOrWhiteSpace(movieDescription))
            {
                properDescription = true;
            }

            bool properPrice = false;
            double moviePrice = 0;
            try
            {
                moviePrice = Convert.ToDouble(moviePriceBox.Text.Trim());
                properPrice = true;
            }
            catch (Exception)
            { }

            if (properTitle && properPrice && properDescription)
            {
                string oldMovieTitle = movieListView.CurrentRow.Cells[1].Value.ToString();
                string oldMovieDescription = movieListView.CurrentRow.Cells[2].Value.ToString();
                string oldMoviePrice = movieListView.CurrentRow.Cells[3].Value.ToString();
                int selectedMovieID = int.Parse(movieListView.CurrentRow.Cells[0].Value.ToString());
                cinemaWcf.UpdateMovie(selectedMovieID, movieTitle, movieDescription, moviePrice);
                clearMovieTextBoxes();
                loadMovies();
                MessageBox.Show("Movie was edited from Title: \"" + oldMovieTitle + "\", Description: \"" + oldMovieDescription + "\" and Price: \"" + oldMoviePrice + "\", to Title: \"" + movieTitle + "\", Description: \"" + movieDescription + "\" and Price: \"" + moviePrice + "\"", "Movie Edit Succeeded!");
            }
            else
            {
                string errorMessages = "";
                if (!properTitle)
                {
                    errorMessages += "missing title input";
                }
                if (!properDescription)
                {
                    if (!properTitle && !properPrice)
                    {
                        errorMessages += ", missing description input";
                    }
                    else if (!properTitle && properPrice)
                    {
                        errorMessages += " and missing description input";
                    }
                    else
                    {
                        errorMessages += "missing description input";
                    }
                }
                if (!properPrice)
                {
                    if (!properTitle || !properDescription)
                    {
                        errorMessages += " and incorrect price input";
                    }
                    else
                    {
                        errorMessages += "incorrect price input";
                    }
                }
                MessageBox.Show("Movie was not edited due to " + errorMessages + ".", "Movie Edit Cancelled!");
            }
        }

        private void deleteMovie(object sender, EventArgs e)
        {
            DialogResult confirmDelete = MessageBox.Show("Are you sure you want to delete the selected movie?", "Movie Deletion Warning!", MessageBoxButtons.YesNo);
            if (confirmDelete == DialogResult.Yes)
            {
                int selectedMovieID = int.Parse(movieListView.CurrentRow.Cells[0].Value.ToString());
                cinemaWcf.DeleteMovie(selectedMovieID);
                loadMovies();
                MessageBox.Show("Movie with ID: " + selectedMovieID + " has been deleted from the database.", "Attention!");
            }
        }
        #endregion

        #region Order Field Update Methods
        private void FillScreeningBox(object sender, EventArgs e)
        {
            #region To be removed
            //List<CinemaScreening> screeningList = cinemaWcf.GetAllScreenings().ToList();

            //List<CinemaScreening> movieScreenings = new List<CinemaScreening>();

            //int chosenMovieID = int.Parse(orderMovieBox.SelectedValue.ToString());

            ////Find all screenings matching the chosen movie ID.
            //foreach (CinemaScreening screening in screeningList)
            //{
            //    if (screening.MovieID == chosenMovieID)
            //    {
            //        movieScreenings.Add(screening);
            //    }
            //}
            #endregion
            //Input screenings from the chosen movie.
            orderScreeningBox.DataSource = cinemaWcf.GetCurrentScreeningByMovieID(int.Parse(orderMovieBox.SelectedValue.ToString()));
            orderScreeningBox.DisplayMember = "ScreeningStartDateTime";
            orderScreeningBox.ValueMember = "ScreeningID";

            #region To be removed
            //List<CinemaRow> rowList = cinemaWcf.GetAllRows().ToList();

            //int chosenScreeningID = int.Parse(orderScreeningBox.SelectedValue.ToString());

            //List<CinemaAuditorium> auditoriumList = cinemaWcf.GetAllAuditoriums().ToList();

            //int chosenAuditoriumID = 0;

            ////Set the chosen auditorium ID from the chosen screening ID, which is found below.
            //foreach (CinemaScreening screening in screeningList)
            //{
            //    if (screening.ScreeningID == chosenScreeningID)
            //    {
            //        chosenAuditoriumID = screening.AuditoriumID;
            //        break;
            //    }
            //}

            //List<CinemaRow> auditoriumRowList = new List<CinemaRow>();

            ////Get all rows in the chosen auditorium.
            //foreach (CinemaRow row in rowList)
            //{
            //    if (row.AuditoriumID == chosenAuditoriumID)
            //    {
            //        auditoriumRowList.Add(row);
            //    }
            //}
#endregion
            //Input rows from the chosen screenings auditorium.
            orderRowNumberBox.DataSource = cinemaWcf.GetRowsByScreeningID(int.Parse(orderScreeningBox.SelectedValue.ToString()));
            orderRowNumberBox.DisplayMember = "RowNumber";
            orderRowNumberBox.ValueMember = "RowsID";

            #region To be removed
            //foreach (CinemaScreening screening in screeningList)
            //{
            //    if (screening.ScreeningID == chosenScreeningID)
            //    {
            //        chosenAuditoriumID = screening.AuditoriumID;
            //        break;
            //    }
            //}

            //foreach (CinemaRow row in rowList)
            //{
            //    if (row.AuditoriumID == chosenAuditoriumID)
            //    {
            //        auditoriumRowList.Add(row);
            //    }
            //}

            //int chosenRowID = int.Parse(orderRowNumberBox.SelectedValue.ToString());

            //List<CinemaSeat> seatList = cinemaWcf.GetAllSeats().ToList();

            //List<CinemaBookedSeat> bookedSeatList = cinemaWcf.GetAllBookedSeats().ToList();

            //List<CinemaSeat> rowSeatList = new List<CinemaSeat>();

            ////Get all seats that are not booked by row and screening ID.
            //foreach (CinemaSeat seat in seatList)
            //{
            //    if (seat.RowID == chosenRowID)
            //    {
            //        bool seatBooked = false;
            //        foreach (CinemaBookedSeat bookedSeat in bookedSeatList)
            //        {
            //            if (bookedSeat.SeatID == seat.SeatID && bookedSeat.ScreeningID == chosenScreeningID)
            //            {
            //                seatBooked = true;
            //                break;
            //            }
            //        }
            //        if (!seatBooked)
            //        {
            //            rowSeatList.Add(seat);
            //        }
            //    }
            //}
#endregion
            //Input unbooked seats for the chosen row number.
            orderSeatNumberBox.DataSource = cinemaWcf.GetAllSeatsNotBookedByRowID(int.Parse(orderScreeningBox.SelectedValue.ToString()), int.Parse(orderRowNumberBox.SelectedValue.ToString()));
            orderSeatNumberBox.DisplayMember = "SeatNumber";
            orderSeatNumberBox.ValueMember = "SeatID";
        }

        private void FillRowNumberBox(object sender, EventArgs e)
        {
            #region To be removed
            //List<CinemaScreening> screeningList = cinemaWcf.GetAllScreenings().ToList();

            //List<CinemaRow> rowList = cinemaWcf.GetAllRows().ToList();

            //int chosenScreeningID = int.Parse(orderScreeningBox.SelectedValue.ToString());

            //List<CinemaAuditorium> auditoriumList = cinemaWcf.GetAllAuditoriums().ToList();

            //int chosenAuditoriumID = 0;

            ////Get auditorium ID by screening ID.
            //foreach (CinemaScreening screening in screeningList)
            //{
            //    if (screening.ScreeningID == chosenScreeningID)
            //    {
            //        chosenAuditoriumID = screening.AuditoriumID;
            //        break;
            //    }
            //}

            //List<CinemaRow> auditoriumRowList = new List<CinemaRow>();

            ////Get rows by auditorium ID.
            //foreach (CinemaRow row in rowList)
            //{
            //    if (row.AuditoriumID == chosenAuditoriumID)
            //    {
            //        auditoriumRowList.Add(row);
            //    }
            //}
#endregion
            //Input rows from the chosen screenings auditorium.
            orderRowNumberBox.DataSource = cinemaWcf.GetRowsByScreeningID(int.Parse(orderScreeningBox.SelectedValue.ToString()));
            orderRowNumberBox.DisplayMember = "RowNumber";
            orderRowNumberBox.ValueMember = "RowsID";

            #region To be removed
            //foreach (CinemaScreening screening in screeningList)
            //{
            //    if (screening.ScreeningID == chosenScreeningID)
            //    {
            //        chosenAuditoriumID = screening.AuditoriumID;
            //        break;
            //    }
            //}

            ////Get all rows in the chosen auditorium.
            //foreach (CinemaRow row in rowList)
            //{
            //    if (row.AuditoriumID == chosenAuditoriumID)
            //    {
            //        auditoriumRowList.Add(row);
            //    }
            //}

            //int chosenRowID = int.Parse(orderRowNumberBox.SelectedValue.ToString());

            //List<CinemaSeat> seatList = cinemaWcf.GetAllSeats().ToList();

            //List<CinemaBookedSeat> bookedSeatList = cinemaWcf.GetAllBookedSeats().ToList();

            //List<CinemaSeat> rowSeatList = new List<CinemaSeat>();

            //foreach (CinemaSeat seat in seatList)
            //{
            //    if (seat.RowID == chosenRowID)
            //    {
            //        bool seatBooked = false;
            //        foreach (CinemaBookedSeat bookedSeat in bookedSeatList)
            //        {
            //            if (bookedSeat.SeatID == seat.SeatID && bookedSeat.ScreeningID == chosenScreeningID)
            //            {
            //                seatBooked = true;
            //                break;
            //            }
            //        }
            //        if (!seatBooked)
            //        {
            //            rowSeatList.Add(seat);
            //        }
            //    }
            //}
#endregion
            //Input unbooked seats for the chosen row number.
            orderSeatNumberBox.DataSource = cinemaWcf.GetAllSeatsNotBookedByRowID(int.Parse(orderScreeningBox.SelectedValue.ToString()), int.Parse(orderRowNumberBox.SelectedValue.ToString()));
            orderSeatNumberBox.DisplayMember = "SeatNumber";
            orderSeatNumberBox.ValueMember = "SeatID";
        }

        private void FillSeatNumberBox(object sender, EventArgs e)
        {
            #region To be removed
            //int chosenScreeningID = int.Parse(orderScreeningBox.SelectedValue.ToString());

            //List<CinemaRow> rowList = cinemaWcf.GetAllRows().ToList();

            //List<CinemaScreening> screeningList = cinemaWcf.GetAllScreenings().ToList();

            //int chosenAuditoriumID = 0;

            //foreach (CinemaScreening screening in screeningList)
            //{
            //    if (screening.ScreeningID == chosenScreeningID)
            //    {
            //        chosenAuditoriumID = screening.AuditoriumID;
            //        break;
            //    }
            //}

            //List<CinemaRow> auditoriumRowList = new List<CinemaRow>();

            //foreach (CinemaRow row in rowList)
            //{
            //    if (row.AuditoriumID == chosenAuditoriumID)
            //    {
            //        auditoriumRowList.Add(row);
            //    }
            //}

            //int chosenRowID = int.Parse(orderRowNumberBox.SelectedValue.ToString());

            //List<CinemaSeat> seatList = cinemaWcf.GetAllSeats().ToList();

            //List<CinemaBookedSeat> bookedSeatList = cinemaWcf.GetAllBookedSeats().ToList();

            //List<CinemaSeat> rowSeatList = new List<CinemaSeat>();

            //foreach (CinemaSeat seat in seatList)
            //{
            //    if (seat.RowID == chosenRowID)
            //    {
            //        bool seatBooked = false;
            //        foreach (CinemaBookedSeat bookedSeat in bookedSeatList)
            //        {
            //            if (bookedSeat.SeatID == seat.SeatID && bookedSeat.ScreeningID == chosenScreeningID)
            //            {
            //                seatBooked = true;
            //                break;
            //            }
            //        }
            //        if (!seatBooked)
            //        {
            //            rowSeatList.Add(seat);
            //        }
            //    }
            //}
#endregion
            //Input unbooked seats for the chosen row number.
            orderSeatNumberBox.DataSource = cinemaWcf.GetAllSeatsNotBookedByRowID(int.Parse(orderScreeningBox.SelectedValue.ToString()), int.Parse(orderRowNumberBox.SelectedValue.ToString()));
            orderSeatNumberBox.DisplayMember = "SeatNumber";
            orderSeatNumberBox.ValueMember = "SeatID";
        }
        #endregion
    }
}